package com.lovo.test.JAVAIO.Io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Copy {
    private FileReader fis;//字符输入
    private BufferedReader br;//字符按行输入
    private FileWriter fos;//字符输出
    private FileWriter fos1;//字符输出

    public static void main(String[] args) {
        Copy co = new Copy();
//        co.copy();
        co.add();
    }

    //文件拷贝
    public void copy() {
        try {
            fis = new FileReader("D:/a.txt");
            fos = new FileWriter("D:/b.txt");
            int b = 0;
            while ((b = fis.read()) != -1) {
                fos.write(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }


    }

    //追加文字
    public void add(){
        Scanner scan = new Scanner(System.in);
        System.out.println("输入追加文字");
        String characters = scan.next();
        try {
            fos1 = new FileWriter("D:/b.txt",true);
            fos1.append(characters);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fos1!=null){
                try {
                    fos1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}


